package com.example.controller;

import com.example.entity.ElevatorFileInfo;
import com.example.service.ElevatorFile;
import com.example.util.AipUtil;
import com.example.util.ResultUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.core.env.Environment;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wang on 2018/3/31.
 *
 */
@RestController
public class ElevatorFileInfoController {
    @Autowired
    ElevatorFile elevatorFile;

    @Autowired
    private Environment environment;

    @ApiOperation(value = "上传电梯文档图片",notes = "上传电梯文档图片")
    @RequestMapping(value="api/elevatorFileInfo/upload",method = RequestMethod.POST)
    Map<String,Object> fileInfoUpload(@RequestBody ElevatorFileInfo elevatorFileInfo){
        return elevatorFile.elevatorFileUpload(elevatorFileInfo);
    }

    @ApiOperation(value = "查询电梯文档图片",notes = "查询电梯文档图片")
    @RequestMapping(value="api/elevatorFileInfo/elevatorQuery",method = RequestMethod.POST)
    Map<String,Object> fileInfoQuery(@RequestBody Map map){
        String elevatorNum = map.get("num").toString();
        return elevatorFile.elevatorFileQuery(elevatorNum);
    }

    @ApiOperation(value = "根据图片获取下次年检日期",notes = "根据图片获取下次年检日期")
    @RequestMapping(value="api/elevatorFileInfo/getNextCheckDate",method = RequestMethod.POST)
    Map<String,Object> getNextCheckDate(@RequestBody String path){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("nextCheckDate",AipUtil.getNextCheckDate( environment.getProperty("upload",String.class)+path));
        return ResultUtil.returnSuccess("获取成功",map);
    }
}
